<template>
	<view class="wrap">
		<u-parse :content="richText" ></u-parse>
	</view>
</template>

<script>
	
	/**
	 * 引入工具类
	 */
	import cont from '../../utils/Constant.js'
	import cache from '../../utils/ACache.js'
	
	export default {
		data() {
			return {
				title: '',
				richText: ''
			}
		},
		/**
		 * 接收传递过来的值
		 */
		onLoad(options) {
			//设置标题
			uni.setNavigationBarTitle({title:options.title});
			//设置内容
			try{
				let text = `<style>img{width:100%;height:auto;}</style>`+ cache.getAsString(cont.CACHE_RICH_TEXT)
				this.richText = this.formatImg(text)
				
				//清空
				cache.remove(cont.CACHE_RICH_TEXT)
			}catch(e){
				console.log('解析后：----------------->',e);
			}
		},
		methods: {
			/**
			 * 调整富文本样式
			 */
			formatImg(html) {
				var newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
					var match = match.replace(/style=\"(.*)\"/gi, 'style="max-width:100%;height:auto"');
					return match;

				});
				return newContent;
			},
		}
	}
</script>

<style>
	.wrap{
		width: 750rpx;
		height: 100%;
		overflow-y: scroll;
		background-color: white;
		box-sizing: border-box;
		padding: 30rpx;
	}
</style>
